﻿using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Text;

namespace Cloak.Mvp.Autofac
{
	/// <summary>
	/// Refers by type and key to a presenter which can be bound to a view
	/// </summary>
	public class KeyedPresenterReference : PresenterReference
	{
		/// <summary>
		/// Initializes a reference to the specified presenter type with the specified key
		/// </summary>
		/// <param name="type">The type of presenter bound to the view</param>
		/// <param name="key">The key of presenter bound to the view</param>
		public KeyedPresenterReference(Type type, object key) : base(type)
		{
			Contract.Requires(key != null);

			Key = key;
		}

		/// <summary>
		/// Gets the key of the presenter bound to the view
		/// </summary>
		public object Key { get; private set; }

		/// <summary>
		/// Gets the site at which the view is bound to the presenter
		/// </summary>
		/// <param name="view">The view to which the presenter is bound</param>
		/// <returns>The site at which the view is bound to the presenter</returns>
		protected override PresenterSite GetSite(object view)
		{
			return new KeyedPresenterSite(Type, Key, view);
		}
	}
}